package com.itheima.dao;

import com.itheima.domain.Question;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

//@Mapper
//@Repository
public interface QuestionDao {

    @Insert("insert into question values (null, #{title}, #{description}, #{coin}, #{uid}, #{createtime}, #{isUp})")

    void save(Question question);

    @Update("update question set title = #{title}, description = #{description}, isUp = #{is_up} where qid = #{qid}")
    int update(Question question);

    @Delete("delete from question where qid = #{qid}")
    int delete(Integer id);

    @Select("select * from question where qid = #{qid}")
    Question getById(Integer qid);

    @Select("select * from question ")
    List<Question> getAll();

    //根据标题查询帖子总数
    @Select("select count(*) from question WHERE title LIKE CONCAT('%',#{title},'%')")
    int selectTotalCount(String title);

//    根据当前页第几页（beginPage），每页数量（pageCount），标题 ，查询帖子集合
    @Select("select * from question  WHERE title LIKE CONCAT('%',#{title},'%') LIMIT #{beginPage} , #{pageCount}")
    List<Question> getByPage(@Param("beginPage") Integer beginPage, @Param("pageCount")Integer pageCount, @Param("title")String title);

    @Select("select * from question WHERE title LIKE CONCAT('%',#{title},'%')")
    List<Question> getAllQues(String title);

    @Update("update question set isUp = #{isUp} where qid = #{qid}")
    int updateStatus(@Param("isUp") int isUp, @Param("qid")int qid);

    //查询所有的置顶帖子
    @Select("select * from question where isUp = 1")
    List<Question> getAllUp();

    @Select("select * from question where uid = #{uid}")
    List<Question> getByUid(Integer uid);
}
